package javasec.contempt.actions;

import javasec.contempt.consoles.SeedShellConsole;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;



public class ConsoleViewAction extends Action implements ISelectionListener,
		IWorkbenchAction
{
	private final IWorkbenchWindow window;
	public final static String ID="javasec.contempt.ConsoleViewAction";
	//private IStructuredSelection selection;
	
	public ConsoleViewAction(IWorkbenchWindow window)
	{
		this.window=window;
		setId(ID);
		setText("Console");
		setToolTipText("santa43622");
		
		window.getSelectionService().addSelectionListener(this);
	}
	
	public void selectionChanged(IWorkbenchPart part, ISelection selection)
	{
	}

	public void dispose()
	{
		window.getSelectionService().removeSelectionListener(this);
	}

	public void run()
	{
		IConsoleManager consoleManager=ConsolePlugin.getDefault().getConsoleManager();
		if(consoleManager.getConsoles().length>0)
			consoleManager.showConsoleView(consoleManager.getConsoles()[0]);
	}
}
